﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.ComponentModel;

namespace Oliver.Controls
{
    public partial class OnlineStateControl : UserControl
    {
        public OnlineStateControl()
        {
            InitializeComponent();

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            CheckState();

            _timer = new DispatcherTimer();
            _timer.Interval = new TimeSpan(0, 0, 10);
            _timer.Tick += timer_Tick;
            _timer.Start();

            //App.Current.ExecutionStateChanged += new EventHandler(Current_ExecutionStateChanged);
        }

        void Current_ExecutionStateChanged(object sender, EventArgs e)
        {
            CheckState();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            CheckState();
        }

        private DispatcherTimer _timer;
        private bool _lastState = false;

        private void CheckState()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            //if (_lastState != App.Current.RunningOffline)
            //{
            //    _lastState = App.Current.RunningOffline;
            //    if (App.Current.RunningOffline == true)
            //    {
            //        VisualStateManager.GoToState(this, "OfflineState", true);
            //    }
            //    else
            //    {
            //        VisualStateManager.GoToState(this, "OnlineState", true);
            //    }
            //}
        }
    }
}
